package com.lin.subject.infra.basic.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lin.subject.infra.basic.mapper.SubjectLabelDao;
import com.lin.subject.infra.basic.entity.SubjectLabel;
import com.lin.subject.infra.basic.service.SubjectLabelService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 题目标签表(SubjectLabel)表服务实现类
 *
 * @author makejava
 * @since 2024-10-19 23:53:30
 */
@Service("subjectLabelService")
public class SubjectLabelServiceImpl extends ServiceImpl<SubjectLabelDao, SubjectLabel> implements SubjectLabelService {

    @Resource
    private SubjectLabelDao subjectLabelDao;

    @Override
    public int add(SubjectLabel subjectLabel) {
        return subjectLabelDao.insert(subjectLabel);
    }

    @Override
    public int update(SubjectLabel subjectLabel) {
        return subjectLabelDao.updateById(subjectLabel);
    }

    @Override
    public int delete(Long id) {
        return subjectLabelDao.deleteById(id);
    }

    @Override
    public List<SubjectLabel> queryLabelByCategoryId(String categoryId) {
        LambdaQueryWrapper<SubjectLabel> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SubjectLabel::getCategoryId, categoryId);

        return subjectLabelDao.selectList(queryWrapper);
    }

    /**
     * 根据ids,查询列表
     *
     * @param labelIds
     * @return
     */
    @Override
    public List<SubjectLabel> batchQueryById(List<Long> labelIds) {
        return lambdaQuery().in(SubjectLabel::getId, labelIds).list();
    }

    @Override
    public List<SubjectLabel> queryByCondition(SubjectLabel subjectLabel) {
        return this.subjectLabelDao.queryByCondition(subjectLabel);
    }

    /**
     * 根据条件查询标签列表
     *
     * @param subjectLabel
     * @return
     */
    @Override
    public List<SubjectLabel> findListByCondition(SubjectLabel subjectLabel) {
        return lambdaQuery()
                .eq(Objects.nonNull(subjectLabel), SubjectLabel::getCategoryId, subjectLabel.getCategoryId())
                .list();
    }
}

